package com.hospital.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;

public class SelectServletByUser extends HttpServlet {
	//添加用户的时候防止选择
	public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		response.setContentType("text/xml");
	    response.setHeader("Cache-Control", "no-cache");
	    request.setCharacterEncoding("UTF-8");
	    response.setCharacterEncoding("UTF-8");
	    String targetId = request.getParameter("root").toString();
	    // 获得请求中参数为root的值
	    String xml_start = "<selects>";
	    String xml_end = "</selects>";
        String xml = "";
	    if (targetId.equalsIgnoreCase("0")){
	           xml = "<select><value>0</value><text>请选择</text></select>";
	    } else if (targetId.equalsIgnoreCase("2")){
	    	String sql = "select * from t_department where type='科室'";//如果是在职医生的情况选择的就只是科室
		 	List<Map<String, Object>> list = DbUtil.find(sql);
			Map<String, Object> map = null;
			for (int i = 0; i < list.size(); i++) {
				map = (Map<String, Object>)list.get(i);
				xml += "<select><value>"+map.get("name")+"</value><text>"+map.get("name")+"</text></select>";
			}
	    } else if (targetId.equalsIgnoreCase("3")){
	           xml = "<select><value>住院部</value><text>住院部</text></select>";
	    } else if (targetId.equalsIgnoreCase("4")){
	           xml = "<select><value>信息技术中心</value><text>信息技术部门</text></select>";
	    } else if (targetId.equalsIgnoreCase("7_1")||targetId.equalsIgnoreCase("7_2")){
	           xml = "<select><value>药物仓库</value><text>药物仓库</text></select>";
	    } else if (targetId.equalsIgnoreCase("8_1")||targetId.equalsIgnoreCase("8_2")){
	           xml = "<select><value>财务科</value><text>财务部门</text></select>";
	    }
	    String last_xml = xml_start + xml + xml_end;
	    response.getWriter().write(last_xml);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		doGet(request, response);
	}
}